//go:build wireinject

package main

import (
	"github.com/google/wire"
	"webook/internal/ioc"
	"webook/internal/job"
	"webook/internal/repository"
	"webook/internal/repository/cache"
	"webook/internal/repository/dao"
	article2 "webook/internal/repository/dao/article"
	"webook/internal/service"
	"webook/internal/web"
)

func InitApp() *ioc.App {
	wire.Build(
		// 初始化数据库连接
		ioc.InitDB, ioc.InitRedis,
		// dao层
		dao.NewUserDAO, article2.NewGORMArticleDAO, dao.NewGORMInterActiveDAO,
		// cache层
		cache.NewUserCache, cache.NewCodeCache, cache.NewRedisArticleCache, cache.NewRedisInterActiveCache, cache.NewRedisRankingCache, cache.NewLocalRankingCache,
		// repo层
		repository.NewCodeRepository, repository.NewUserRepository, repository.NewCachedArticleRepository, repository.NewCachedInteractiveRepository, repository.NewCachedRankingRepository,
		// service层
		ioc.InitSMSService, service.NewSmsCodeService, service.NewUserService, ioc.InitWechatService, service.NewArticleService, service.NewInterActiveService, service.NewBatchRankingService,
		// web层
		web.NewUserHandler, web.NewOauth2WechatHandler, web.NewJwtHandler, web.NewArticleHandler,
		// job层
		job.NewRankingJob,
		// server层
		ioc.InitWebServer,
		// ratelimit
		ioc.InitRateLimiter,
		// 中间件层
		ioc.InitMiddlewares,
		// zap 层
		ioc.InitUserZap,
		// job 层
		ioc.InitJob,
		// app层
		ioc.InitApp,
	)
	return new(ioc.App)
}
